<?php
namespace app\service\data;

use app\service\models as models;
use function GuzzleHttp\json_encode;
use function GuzzleHttp\json_decode;

class Setting { 
    public $_config;
    
    public function __construct() {
        $this->_config = new  models\Config();
    }
    
    //获取banner list
    public function GetBannerList($arrInput) {
        $ret = $this->_config->find()->where(['key'=>'bannerlist'])->one();
        return $ret ? json_decode($ret->value) : [];
    }
    
    //设置banner list
    public function SetBannerList($arrInput) {
        $ret = $this->_config->find()->where(['key'=>'bannerlist'])->one();
        if ($ret) {
            $ret->value = json_encode($arrInput);
            $ret->save();
        } else {
            $this->_config->key = 'bannerlist';
            $this->_config->value = json_encode($arrInput);
            $ret = $this->_config->save();
        }
        
        return $ret ? 1 : 0;
    }
}